import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import "./index.less";
import { useTranslation } from "react-i18next";
import { SupplierApi } from "@/api/erp/purchase/supplier";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.purchasingManagement.supplierInfo";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.name`),
			field: "name",
			component: "Input"
		},
		{
			label: t(`${en_vi}.mobile`),
			field: "mobile",
			component: "Input"
		},
		{
			label: t(`${en_vi}.telephone`),
			field: "telephone",
			component: "Input"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.name`),
			dataIndex: "name"
		},
		{
			title: t(`${en_vi}.contact`),
			dataIndex: "contact"
		},
		{
			title: t(`${en_vi}.mobile`),
			dataIndex: "mobile"
		},
		{
			title: t(`${en_vi}.telephone`),
			dataIndex: "telephone"
		},
		{
			title: t(`${en_vi}.email`),
			dataIndex: "email"
		},
		{
			title: t(`${en_vi}.remark`),
			dataIndex: "remark"
		},
		{
			title: t(`${en_vi}.sort`),
			dataIndex: "sort"
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: SupplierApi.getSupplierPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 8 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setSuplerList(orderItem[0]);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
